﻿using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Webservice.Comm;

namespace HX_WebService_Core.Comm
{
    public static class SqlsugarSetup
    {
        public static void AddSqlsugarSetup(this IServiceCollection services)
        {
            if (services == null) throw new ArgumentNullException(nameof(services));
            services.AddScoped<ISqlSugarClient>(o =>
            {
                // 连接字符串
                var listConfig = new List<ConnectionConfig>();
                // 从库
                //var listConfig_Slave = new List<SlaveConnectionConfig>();

                listConfig.Add(new ConnectionConfig()
                {
                    ConfigId = "SQL",
                    ConnectionString = BaseDBConfig.ConnectionString,
                    DbType = DbType.MySql,
                    IsAutoCloseConnection = true,
                    IsShardSameThread = false,
                    MoreSettings = new ConnMoreSettings()
                    {
                        IsAutoRemoveDataCache = true
                    }
                });
                return new SqlSugarClient(listConfig);
            });
        }
    }
}
